<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="cn.school.mybaits.Dao.StudentDao"%>
<%@page import="cn.school.mybaits.entity.Student"%>
<%@page import="cn.school.mybaits.xml.MyBatisUtil"%>
<%@page import="org.apache.ibatis.session.SqlSession"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<%
		request.setCharacterEncoding("utf-8");
		String sname = request.getParameter("sname");
		String sex = request.getParameter("sex");
		String telephone = request.getParameter("telephone");
		String qq = request.getParameter("qq");
		String wechat = request.getParameter("wechat");
		String grade = request.getParameter("gradeid");
		int gradeid = Integer.parseInt(grade);
		String enterdate = request.getParameter("enterdate");
		String fromcity = request.getParameter("fromcity");
		String birthday = request.getParameter("birthday");
		String address = request.getParameter("address");
		String pass = request.getParameter("pass");
	

		SqlSession sess = MyBatisUtil.get();
		StudentDao studentDao = sess.getMapper(StudentDao.class);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("sname", sname);
		map.put("sex", sex);
		map.put("telephone", telephone);
		map.put("qq", qq);
		map.put("wechat", wechat);
		map.put("gradeid", gradeid);
		map.put("enterdate", new SimpleDateFormat("yyyy-MM-dd").parse(enterdate));
		map.put("fromcity", fromcity);
		map.put("birthday", new SimpleDateFormat("yyyy-MM-dd").parse(birthday));
		map.put("address", address);
		map.put("pass", pass);

		int a = studentDao.add(map);
		if (a > 0) {
			out.print("<h1>添加成功</h1>");
		} else {
			out.print("<h1>添加失败,重新<a href='Student.jsp'>添加</a></h1>");
		}
		MyBatisUtil.close(sess);
	%>
</body>
</html>